/*
 * Copyright 2006-2008 Michele Mostarda ( michele.mostarda@gmail.com ).
 * All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.graphnav.aggregator.swing;

import org.graphnav.aggregator.model.Plugin;
import org.graphnav.aggregator.model.impl.FSPlugin;
import org.graphnav.swing.GraphPanel;
import org.graphnav.swing.GridNodeArranger;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Frame;

/**
 * Defines the aggregator main access point.
 */
public class Aggregator extends JPanel {

    private Plugin plugin;

    private GraphPanel graphPanel;

    private JFrame frame;

    public Aggregator(Plugin p) {
        plugin = p;
        graphPanel = new GraphPanel( p.getModel() );
        graphPanel.setMode(GraphPanel.VIEW_ALL);
        graphPanel.arrange(new GridNodeArranger(), new GridNodeArranger.Options(10));
        setLayout(new BorderLayout());
        add(graphPanel);
    }

    public Frame getContainerFrame() {
        if(frame == null) {
            frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            frame.setLocation(100, 100);
            frame.setSize(800, 600);
            frame.getContentPane().add(this);
        }
        return  frame;
    }

    public static void main(String[] args) {
        FSPlugin fsp = new FSPlugin();
        Aggregator pn = new Aggregator(fsp);
        pn.getContainerFrame().setVisible(true);
    }

}
